import axios from 'axios'
import router from '../router/index'
//获取环境变量
const env = import.meta.env
let baseURL:any = env.VITE_APP_BASE_API

const instance = axios.create({
  timeout: 50000,
  baseURL: baseURL
});

instance.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
instance.defaults.headers.common['webMark'] = 'noToekn';

instance.interceptors.request.use(function (config) {
  // const currObj:any = config;

  // let token = sessionStorage.getItem('token')
  // if(token) {
  //   currObj.headers['authorization'] = token
  // }
  return config;
}, function (error) {
  return Promise.reject(error);
});


instance.interceptors.response.use(function (response) {
  const {data} = response
  if(data.code === "10101") {
    router.push('/login')
    return response;
  }
  return response;
}, function (error) {
  return Promise.reject(error);
});

export default instance